﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TarreOA.TarreOAModels;
namespace TarreOA.TarreOADAL
{
    public class Flow_FindFormByTypeDAO
    {

        //根据 id 查询表单

        public DataSet getFormById(string id)
        {
            SqlConnection conn = SQLManager.GetConn();
            string str = "select flow_type.flow_name as fname,flow_forms.form_name as TheName ,flow_forms.id as theid,flow_newflow.base_flow_id as bid from flow_newflow left outer join flow_forms on flow_forms.id=flow_newflow. form_id INNER JOIN flow_type on flow_type.id=flow_newflow.base_flow_id where flow_newflow.base_flow_id=" + id;
                SqlDataAdapter myda = new SqlDataAdapter(str, conn);
                DataSet ds = new DataSet();
                myda.Fill(ds, "lis");

                conn.Close();
                conn.Dispose();
                return ds;          
        }
        public string getFlowName(string id) {
            SqlConnection conn = null;
            SqlDataReader dr = null;
            String detail = "您访问的内容不存在或已被删除";
            try
            {
                conn = SQLManager.GetConn();
                conn.Open();

                SqlCommand cmd = new SqlCommand("select flow_name from flow_type where id= @id", conn);
                cmd.Parameters.Add(new SqlParameter("@id", id));
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    detail = (String)dr["flow_name"];

                }
                dr.Close();
                conn.Close();
                dr.Dispose();
                conn.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            return detail;
        }
    }
}
